﻿using System.Linq;
using System.Web.Mvc;
using DNT.RavenQA.Web.Infrastructure.Indexing;
using DNT.RavenQA.Web.ViewModels;
using log4net;
using Raven.Client;
using Raven.Client.Linq;

namespace DNT.RavenQA.Web.Controllers
{
    public class SideBarController : ControllerBase
    {
        public SideBarController(IDocumentSession session, ILog log)
            : base(session, log)
        {
        }

        [ChildActionOnly]
        public ActionResult TagList()
        {
            var model = new TagListViewModel
                            {
                                Items = DocumentSession.Query<QuestionsTagListIndex.ReduceResult, QuestionsTagListIndex>()
                                    .OrderByDescending(t => t.Count)
                                    .Take(10)
                                    .ToList()
                            };

            return View(model);
        }
    }
}